namespace PHSRAG.Insight21.ClinicalTrials.Controls
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
   using PHSRAG.Insight21.Admin;
   using PHSRAG.Insight21.CDS;
   using PHSRAG.Insight21.Policy;
   
   /// <summary>
	/// The BudgetBuilderOverview control is used to display summary information to the user after
	/// the initial setup of the budget is complete.
	/// </summary>
	public partial class BudgetBuilderOverviewControl : System.Web.UI.UserControl
	{
      #region Instance Variabled
      private Budget budget;
      private ICachePolicy cachePolicy;
      private RefCodes refCodes;
      #endregion

      #region Private Methods
      /// <summary>
      /// Runs on Page.Load, sets up all controls
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      protected void OnPageLoad(object sender, System.EventArgs e)
      {
         InitializeControls( );
      }

      /// <summary>
      /// Initialize controls.  Public here so it can be re-called by BudgetSetup after a save
      /// </summary>
      public void InitializeControls( )
      {
         budget = (Budget)cachePolicy.GetCachedObject( Budget.CacheKey );

         ICachePolicy applicationCachePolicy = (ICachePolicy)Application[Policy.Names.ApplicationCachePolicyKey];
         refCodes = (RefCodes)applicationCachePolicy.GetCachedObject( RefCodes.CacheKey );

         if ( budget != null && budget.Id != 0 )
         {
		    budgetId.Text = budget.Id.ToString();
            shortTitle.Text = budget.StudyShortTitle;
            folderNumber.Text = budget.FolderNumber;
            lastModifiedDate.Text = budget.LastModifiedDate.ToString( );

            User pi = new User( this.cachePolicy );
            pi.Load( Utility.DataAccess.GetConnectionString( ), budget.PIPersonId );
            PIName.Text = string.Format( "{0}, {1}", pi.LastName, pi.FirstName );

            RefCode institutionCode = refCodes.GetRefCode( budget.InstitutionCode );
            institution.Text = institutionCode.Meaning;
         }
      }
      #endregion

      #region Overrides
      /// <summary>
      /// Set the status after postback data is processed since it may change on postback
      /// </summary>
      /// <param name="e"></param>
      protected override void OnPreRender(EventArgs e)
      {
         RefCode statusCode = refCodes.GetRefCode( budget.StatusCode );
         status.Text = statusCode.Meaning;

         base.OnPreRender (e);
      }
      #endregion

		#region Web Form Designer generated code
      /// <summary>
      /// Handler for the event raised when the page is being initialized.
      /// Save the current cachePolicy
      /// </summary>
      /// <param name="e"></param>
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
         cachePolicy = (Policy.ICachePolicy)Session[Policy.Names.CachePolicyKey];
      }
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.OnPageLoad);

		}
		#endregion
	}
}
